package com.cqgcxy.shopping.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqgcxy.shopping.common.CommException;
import com.cqgcxy.shopping.common.JdbcUtils;
import com.cqgcxy.shopping.domain.Administrator;


public class Administratordao {
	private Logger logger=LoggerFactory.getLogger(getClass());
	
	private Administrator rowMap(ResultSet rs) throws SQLException{
		Administrator administrator=new Administrator();
		administrator.setID(rs.getInt("ID"));
		administrator.setAdmincode(rs.getString("admincode"));
		administrator.setAdminid(rs.getString("adminid"));
		administrator.setAdminpassword(rs.getString("adminpassword"));
		return administrator;
		
	}
	
	public Administrator findBycode(String admincode) {
		Connection conn = JdbcUtils.getConnection();
		PreparedStatement pS=null;
		ResultSet rs=null;
	try {
		String sql="select * from administrator where admincode=? and adminpassword=?";
		pS=conn.prepareStatement(sql);
		pS.setString(1, admincode);
		logger.debug(sql);
		rs=pS.executeQuery();
		
		while(rs.next()) {
			return rowMap(rs);
		}
	}catch (Exception e) {
		logger.error(e.getMessage());
		throw new CommException(e.getMessage());
	}finally {
		JdbcUtils.close(conn, pS, rs);
	}
	return null;
	}

	public static Administrator findByCode(String admincode, String adminpassword) {
		// TODO Auto-generated method stub
		return null;
	}
	

	
	
	

}
